package asteroids.model.programs.expressions.ComposedExpressions.BinaryExpressions;

import asteroids.model.programs.expressions.BasicExpression;
import asteroids.model.programs.expressions.Expression;
import asteroids.model.programs.expressions.BasicExpressions.DoubleLiteral;
import asteroids.model.programs.expressions.ComposedExpressions.BinaryExpression;
import asteroids.model.programs.types.Type;

public class Subtraction extends BinaryExpression {
	
	/**
	 * Initialize the Subtraction object
	 * 
	 * @param leftExp
	 * 			The left operand of this expression
	 * @param rightExp
	 * 			The right operand of this expression
	 * @effect ...
	 * 			|super(leftExp, rigthExp)
	 */
	public Subtraction(Expression leftExp, Expression rightExp, int line, int column){
		super(leftExp, rightExp, line, column);
	}
	
	
	/**
	 * Returns the symbol for this Expression, namely -
	 * 
	 * @return ...
	 * 			| return "-"
	 */
	@Override
	public String getOperatorSymbol() {
		return "-";
	}

	/**
	 * Returns the BasicExpression of type DoubleLiteral with the value of the subtraction
	 * 
	 * @return ...
	 * 			| result.equals(new DoubleLiteral(getLeftOperand().getResult().getValue()-
	 * 												getRightOperand().getResult.getValue())
	 */
	@Override
	public BasicExpression getResult() {
		double leftValue = ((DoubleLiteral)getLeftOperand().getResult()).getValue();
		double rightValue = ((DoubleLiteral)getRightOperand().getResult()).getValue();
		double resultValue = leftValue - rightValue;
		BasicExpression result = new DoubleLiteral(resultValue, getLine(), getColumn());
		return result;
	}
	
	@Override
	public Type getType(){
		return Type.DOUBLE;
	}
	
	@Override
	public Type[] getOperandType(){
		return new Type[]{Type.DOUBLE};
	}

}
